import { fromJS } from 'immutable';
import {CHANGE_HOME_DATA, LOAD_LIST, SHOW_BACK} from './actionTypes'

const defaultState = fromJS({
  topicList: [],
  articleList: [],
  recommendList: [],
  page: 1,
  showBack: false
});

export default (state = defaultState, action) => {
  switch (action.type) {
    case CHANGE_HOME_DATA:
      return state.merge({
        topicList: fromJS(action.topicList),
        articleList: fromJS(action.articleList),
        recommendList: fromJS(action.recommendList)
      });
    case LOAD_LIST:
      return state.merge({
        page: action.page,
        articleList: state.get('articleList').concat(fromJS(action.list))
      });
    case SHOW_BACK:
      return state.set('showBack', action.bool);
    default:
      return state
  }
}